/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.mycompany.j2eem.service.wucyservice;

import com.mycompany.j2eem.Entity.JsonResult;
import com.mycompany.j2eem.Entity.ResultCode;
import com.mycompany.j2eem.Entity.UserMessage;
import com.mycompany.j2eem.Mapper.wcymapper.LoginMapper;
import com.mycompany.j2eem.Mapper.wcymapper.MessageMapper;
import java.util.Date;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 *
 * @author asus
 */
@Service
public class MessageService {
    @Autowired
    MessageMapper messageMapper;
    @Autowired
    LoginMapper loginMapper;
            
    //获取用户接受到的消息
    public JsonResult get_User_Message(String username){
        String account = loginMapper.getAccountId(username);
        List<UserMessage> temp = messageMapper.get_Mymessage(account);
        if(temp.isEmpty()){
            return new JsonResult(ResultCode.SUCCESS,"没有消息");
        }
       
        
        return new JsonResult(ResultCode.SUCCESS,temp);
    }
    
    //已读
    public JsonResult read_Message(String message_id){
        messageMapper.is_read(message_id);
        return new JsonResult(ResultCode.SUCCESS,message_id);
    }
    
    //发送消息
    public JsonResult send_Message(String username,String Account_id_b,String operation){
        String operation_id= null;
        if(operation.equals("关注")){
            operation_id = "1";
        }
        messageMapper.send_message(username, operation_id, Account_id_b, "0");
        return new JsonResult(ResultCode.SUCCESS,"关注成功");
    }
    
}
